package com.yilian.coach.dal.coach.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.yilian.coach.dal.coach.daointerface.AcUserDAO;
import com.yilian.coach.dal.coach.dataobject.AcUserDO;

/**
 * An ibatis based implementation of dao interface
 * <tt>com.yilian.coach.dal.coach.daointerface.AcUserDAO</tt>.
 * 
 * This file is generated by <tt>coach-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>paygw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may be
 * OVERWRITTEN by someone else. To modify the file, you should go to directory
 * <tt>(project-home)/biz/dal/src/conf/dalgen</tt>, and find the corresponding
 * configuration file (<tt>tables/ac_user.xml</tt>). Modify the configuration
 * file according to your needs, then run <tt>coach-dalgen</tt> to generate this
 * file.
 * 
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class IbatisAcUserDAO extends SqlMapClientDaoSupport implements
		AcUserDAO {
	/**
	 * Query DB table <tt>ac_user</tt> for records.
	 * 
	 * <p>
	 * The sql statement for this operation is <br>
	 * <tt>select id, user_name, user_real_name, email, password, user_type, user_status, attend_id, org_id, org_name, phone, mobile, last_login_time, last_login_ip, login_password_error_times, memo, raw_add_time, raw_update_time from yilian_authorization.ac_user where (user_name = ?)</tt>
	 * 
	 * @param userName
	 * @return AcUserDO
	 * @throws DataAccessException
	 */
	public AcUserDO findUserInfoByUserName(String userName)
			throws DataAccessException {

		return (AcUserDO) getSqlMapClientTemplate().queryForObject(
				"MS-AC-USER-FIND-USER-INFO-BY-USER-NAME", userName);

	}

	/**
	 * Query DB table <tt>ac_user</tt> for records.
	 * 
	 * <p>
	 * The sql statement for this operation is <br>
	 * <tt>select id, user_name, user_real_name, email, password, user_type, user_status, attend_id, org_id, org_name, phone, mobile, last_login_time, last_login_ip, login_password_error_times, memo, raw_add_time, raw_update_time from yilian_authorization.ac_user</tt>
	 * 
	 * @return List<AcUserDO>
	 * @throws DataAccessException
	 */
	public List<AcUserDO> queryUserInfoList() throws DataAccessException {

		return getSqlMapClientTemplate().queryForList(
				"MS-AC-USER-QUERY-USER-INFO-LIST", null);

	}

	/**
	 * Update DB table <tt>ac_user</tt>.
	 * 
	 * <p>
	 * The sql statement for this operation is <br>
	 * <tt>update yilian_authorization.ac_user set password=? where (user_name = ?)</tt>
	 * 
	 * @param acUser
	 * @return int
	 * @throws DataAccessException
	 */
	public int updatePassword(AcUserDO acUser) throws DataAccessException {
		if (acUser == null) {
			throw new IllegalArgumentException(
					"Can't update by a null data object.");
		}

		return getSqlMapClientTemplate().update("MS-AC-USER-UPDATE-PASSWORD",
				acUser);
	}

	/**
	 * Query DB table <tt>ac_user</tt> for records.
	 * 
	 * <p>
	 * The sql statement for this operation is <br>
	 * <tt>select * from yilian_authorization.ac_user</tt>
	 * 
	 * @param acUser
	 * @param limitStart
	 * @param pageSize
	 * @return List<AcUserDO>
	 * @throws DataAccessException
	 */
	public List<AcUserDO> queryUserInfoPageList(AcUserDO acUser,
			int limitStart, int pageSize) throws DataAccessException {
		if (acUser == null) {
			throw new IllegalArgumentException(
					"Can't select by a null data object.");
		}

		Map param = new HashMap();

		param.put("acUser", acUser);
		param.put("limitStart", new Integer(limitStart));
		param.put("pageSize", new Integer(pageSize));

		return getSqlMapClientTemplate().queryForList(
				"MS-AC-USER-QUERY-USER-INFO-PAGE-LIST", param);

	}

	/**
	 * Query DB table <tt>ac_user</tt> for records.
	 * 
	 * <p>
	 * The sql statement for this operation is <br>
	 * <tt>select count(id) from yilian_authorization.ac_user</tt>
	 * 
	 * @param acUser
	 * @return long
	 * @throws DataAccessException
	 */
	public long queryUserInfoPageListCount(AcUserDO acUser)
			throws DataAccessException {
		if (acUser == null) {
			throw new IllegalArgumentException(
					"Can't select by a null data object.");
		}

		Long retObj = (Long) getSqlMapClientTemplate().queryForObject(
				"MS-AC-USER-QUERY-USER-INFO-PAGE-LIST-COUNT", acUser);

		if (retObj == null) {
			return 0;
		} else {
			return retObj.longValue();
		}

	}

	/**
	 * 
	 * @param acUser
	 * @throws DataAccessException
	 * @see com.yilian.coach.dal.coach.daointerface.AcUserDAO#saveUserInfo(com.yilian.coach.dal.coach.dataobject.AcUserDO)
	 */
	@Override
	public long saveUserInfo(AcUserDO acUser) throws DataAccessException {
		if (acUser == null) {
			throw new IllegalArgumentException(
					"Can't select by a null data object.");
		}
		getSqlMapClientTemplate().insert("insertUserInfo", acUser);
		return acUser.getId();
	}

	/**
	 * 
	 * @param acUser
	 * @throws DataAccessException
	 * @see com.yilian.coach.dal.coach.daointerface.AcUserDAO#updateUserInfo(com.yilian.coach.dal.coach.dataobject.AcUserDO)
	 */
	@Override
	public void updateUserInfo(AcUserDO acUser) throws DataAccessException {
		if (acUser == null) {
			throw new IllegalArgumentException(
					"Can't update by a null data object.");
		}
		getSqlMapClientTemplate().update("updateUserInfo", acUser);
	}

	/**
	 * 
	 * @param userId
	 * @return
	 * @throws DataAccessException
	 * @see com.yilian.coach.dal.coach.daointerface.AcUserDAO#queryUserInfoById(long)
	 */
	@Override
	public AcUserDO queryUserInfoById(long userId) throws DataAccessException {
		return (AcUserDO) getSqlMapClientTemplate().queryForObject(
				"getUserById", userId);
	}

	@Override
	public void deleteUserByUserId(long id) {
		// TODO Auto-generated method stub
		
	}

}